package com.manbearpig.todue;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
Main class that runs when the application is launched
**/
public class ToDueActivity extends Activity
{
	private Login_Manager lm;
	public boolean test = false;
	
	/** Called when the activity is first created. */
    @Override
	/**
	Method that runs when the app is launched for the first time
	@param savedInstanceState the state of the app the last time it was launched
	**/
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loginscreen);
        lm = new Login_Manager();
    }
    
    /**
     * Click listener for the login button
     * @param view Required param
     */
    public void attemptLogin(View view)
    {
    	lm.setUsername(((EditText) findViewById(R.id.username_TextField)).getText().toString());
    	lm.setPassword(((EditText) findViewById(R.id.password_TextField)).getText().toString());
    	if(lm.attemptLogin(this))
    	{
    		Intent myIntent = new Intent(getApplicationContext(), ToDoListActivity.class);
    		myIntent.putExtra("Username", lm.getUsername());
    		test  = true;
    		startActivity(myIntent);
    	}
    }
    
    public boolean attemptLogin(String user, String pass){
    	lm.setUsername(user);
    	lm.setPassword(pass);
    	return (lm.attemptLogin(this)==true);
    }
    
    /**
     * OnClickListener for creating an account
     * @param view the requested view
     */
    public void onClick(View view)
    {
    	Log.d("Checkpoint", "Made it inside the button press");
    	Intent myIntent = new Intent(getApplicationContext(), CreateAccountActivity.class);
        startActivity(myIntent);   
    }
}